

function queue(tasks)  {
	let promise = Promise.resolve();
	let results = []
	tasks.map(item => {
		promise = promise.then(v => {
			return new Promise((resolve, reject)=> {
				setTimeout(() => {
					console.log(item)
					resolve(item+100);	// fulfilled
				}, 1000)
			})
		})
		results.push(promise)
	})
	return results;
}


var results =  queue([1, 2, 3, 4, 5]);
Promise.all(results).then(res => {
	console.log(res)
}).catch(reason => {
	console.warn('reason = ', reason)
})



